package com.coder.oj.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.oj.admin.mapstruct.CommitMapstruct;
import com.coder.oj.admin.service.CommitService;
import com.coder.oj.admin.vo.CommitVo;
import com.coder.oj.common.core.BaseQuery;
import com.coder.oj.common.core.JsonPage;
import com.coder.oj.common.core.JwtToken;
import com.coder.oj.common.core.R;
import com.coder.oj.common.entity.Commit;
import com.coder.oj.common.mapper.CommitMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = {"提交管理"})
@RestController
@RequestMapping("/commit")
public class CommitController {

    @Autowired
    private CommitService commitService;

    @Autowired
    private CommitMapper commitMapper;

    @Autowired
    private CommitMapstruct commitMapstruct;

    @JwtToken
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public R<JsonPage<CommitVo>> getCommitPage(@RequestBody BaseQuery params) {
        return R.ok().setResult(commitService.getCommitPage(params));
    }

    @JwtToken
    @GetMapping
    @ApiOperation("提交详情")
    public R<CommitVo> getCommitById(@RequestParam("id") Long id) {
        return R.ok().setResult(commitMapstruct.toVO(commitMapper.selectById(id)));
    }
}
